package com.supermap.guangzhou.weifang.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.supermap.guangzhou.weifang.R;
import com.supermap.guangzhou.weifang.entity.FangWuAnquanXinXi;
import com.supermap.guangzhou.weifang.utils.Utils;

import java.util.List;

/**
 * Created by XueQing Wang on 2018/6/29.
 */

public class PuchaViewAdapter extends RecyclerView.Adapter<PuchaViewHolder> {

    private List<FangWuAnquanXinXi> list;
    private LayoutInflater layoutInflater;

    public PuchaViewAdapter( List<FangWuAnquanXinXi> list) {
        this.list = list;
        layoutInflater = LayoutInflater.from(Utils.getContext());
    }

    @NonNull
    @Override
    public PuchaViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.swipe_layout_pucha, parent,false);
        return new PuchaViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PuchaViewHolder holder, int position) {
        FangWuAnquanXinXi fangWuAnquanXinXi = list.get(position);

        holder.tvXzqmc.setText(fangWuAnquanXinXi.getXzqmc());
        holder.tvJqmc.setText(fangWuAnquanXinXi.getJqmc());
        holder.tvFwdz.setText(fangWuAnquanXinXi.getFwdz());
        holder.tvPczt.setText(fangWuAnquanXinXi.getPczt());

        holder.tvPucha.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onPuchaListener!=null){
                    onPuchaListener.onPucha(fangWuAnquanXinXi);
                }
            }
        });
    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    private OnPuchaListener onPuchaListener;

    public void setOnPuchaListener(OnPuchaListener onPuchaListener) {
        this.onPuchaListener = onPuchaListener;
    }

    public interface OnPuchaListener{
        void onPucha(FangWuAnquanXinXi fangWuAnquanXinXi);
    }
}


class PuchaViewHolder extends RecyclerView.ViewHolder {

    TextView tvXzqmc;
    TextView tvJqmc;
    TextView tvFwdz;
    TextView tvPczt;
    TextView tvPucha;

    public PuchaViewHolder(View itemView) {
        super(itemView);
        tvXzqmc = itemView.findViewById(R.id.tv_xzqmc);
        tvJqmc = itemView.findViewById(R.id.tv_jqmc);
        tvFwdz = itemView.findViewById(R.id.tv_fwdz);
        tvPczt = itemView.findViewById(R.id.tv_pczt);
        tvPucha = itemView.findViewById(R.id.tv_pucha);
    }
}
